// packageActivity/activity/activity.js
import { getEstablishInfo,beInvitedInfo,getReferrerInfo,recordScope } from "../../api/activity"
import {
    getEnterpriseList
} from '../../../api/app.js'
import { toast,confirm } from "../../../utils/util"
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabIndex:0,
        qrId:'',
        info:{},
        enterprise:{
            name:'',
            code:'',
            phone:'',
            userName:'',
            area:'',
			id:'',
			companyId: ''
        },
        isInfoPopup:false,
        toView:'',
		bodyTop:'',
		list: [
			{
				icon: '../../assets/img/annul/ico-1.png',
				title: '无卡发薪',
				content: '无需银行卡，入职当日即可发薪，联合微信支付共同打造，一秒批量支付到员工微信零钱'
			},
			{
				icon: '../../assets/img/annul/ico-2.png',
				title: '日结周薪',
				content: '日薪、周薪、月转日独立模块，按系统考勤发放，降低财务90%工作量，从手工到全自动'
			},
			{
				icon: '../../assets/img/annul/ico-3.png',
				title: '电子考勤',
				content: '人脸识别，员工手机打卡可自主设置打卡规则、电子围栏，自动生成考勤报表，彻底摆脱手工做考勤'
			},
			{
				icon: '../../assets/img/annul/ico-4.png',
				title: '便捷记名单',
				content: '告别手工登记、拍照登记员工扫码直接生成花名册批量填写供应商&工价政策，驻厂现场就能做好名单'
			},
			{
				icon: '../../assets/img/annul/ico-5.png',
				title: '简历库',
				content: '电子员工档案，随时随地跟派遣员工沟通，可一键给派遣员工批量发通知，更方便的派遣员工做服务'
			},
			{
				icon: '../../assets/img/annul/ico-6.png',
				title: '电子合同',
				content: '在线一键签约，操作便捷易保存、易查询，相较纸质合同管理成本更低，效率更高。'
			},
			{
				icon: '../../assets/img/annul/ico-7.png',
				title: '预支薪资',
				content: '提供人性化预支服务，有效保障员工日常生活需求，吸引更多求职者，提高员工留存率'
			},
			{
				icon: '../../assets/img/annul/ico-8.png',
				title: '团队协同',
				content: '供应商、经纪人、驻厂、老板共同管理项目，多人实时在线编辑，无缝对接，大幅降低沟通成本'
			}
		]
    },

    onLoad(options){
        console.log('进入啦活动页面',options)
        this.getRect()
        let scene = decodeURIComponent(options.scene).split('=')[1]
        this.setData({
            qrId:scene
        })
        this.getEstablishInfo()
        console.log(this.data.qrId,'scene')
    },
    onRuleTabs(){
        this.setData({
            tabIndex:2,
            toView:'ronus'
        })
    },
    onRonusTabs(){
        this.setData({
            tabIndex:0,
        })
    },
    onProgrammeTabs(){
        this.setData({
            tabIndex:1,
            toView:'programme'
        })
    },
    getEstablishInfo(){
        getReferrerInfo({
            qrCodeId:this.data.qrId
        }).then(res=>{
            console.log(res,'res')
            this.setData({
                info:res
            })
        })
    },
    onEnterpriseInput(event){
        const { value } = event.detail
        getEnterpriseList({
            name:value
        }).then(res=>{
            this.setData({
                tipList:res
            })
        })
    },
    onTapEnter(event){
        const { name,code,area,id } = event.currentTarget.dataset
        this.setData({
            ['enterprise.name']:name,
            ['enterprise.code']:code,
			['enterprise.area']:area,
			['enterprise.companyId']:id,
            tipList:[],
            isSendOutBtn:true
        })
        console.log(this.data.isSendOutBtn,'isSendOutBtn')
    },
    onNameInput(event){
        const { value } = event.detail
        this.setData({
            ['enterprise.userName']:value
        })
    },
    onPhoneInput(event){
        const { value } = event.detail
        this.setData({
            ['enterprise.phone']:value
        })
    },
    onPreciseExtension(){
        if(!this.data.enterprise.userName){
            toast('请填写姓名')
            return
        }
        if(!this.data.enterprise.phone){
            toast('请填写手机号')
            return
        }
        if(!this.data.enterprise.code){
            toast('请选择公司')
            return
        }
        console.log(this.data.enterprise)
        recordScope({
            contactName:this.data.enterprise.userName,
            contactPhone:this.data.enterprise.phone,
            customName:this.data.enterprise.name,
            creditCode:this.data.enterprise.code,
            area:this.data.enterprise.area,
            qrcodeId:this.data.qrId
        }).then(async res=>{
            console.log(res.id || res,'res')
            this.setData({
                ['enterprise.id']:res.id || ''
            })
            await this.cancel()
            console.log(this.data.enterprise)
            wx.navigateTo({
                url: '/packageActivity/pages/annually-success/annually-success',
                success:(res)=>{
                    res.eventChannel.emit('acceptDataFromOpenerPage', { data: this.data.enterprise,type:'manyPeople' })
                    this.cancel()
                }
            })
        })
    },
    cancel(){
        this.setData({
            isInfoPopup:false
        })
    },
    onImmediateUse(){
        this.setData({
            isInfoPopup:true
        })
    },
    getRect () {
        console.log('调用啦')
        wx.createSelectorQuery().select('#the-id').boundingClientRect((rect=>{
            console.log(rect.top)
            this.setData({
                bodyTop:rect.top
            })
            console.log(this.data.bodyTop,'bodyTop')
        })).exec()
        
      },
})